package me.yangbajing.model

object ReqDoc {
  def apply(creator: String): ReqDoc =
    new ReqDoc(creator)

  def apply(doc: MDocument): ReqDoc =
    new ReqDoc(
      doc.creator,
      doc.category,
      doc.title,
      doc.content,
      doc.subtitle,
      doc.description,
      doc.slug,
      doc.tags map (_.split(',').toList) getOrElse Nil)

}

class ReqDoc private(
                      var creator: String,
                      var category: String = "",
                      var title: String = "",
                      var content: String = "",
                      var subtitle: Option[String] = None,
                      var description: Option[String] = None,
                      var slug: Option[String] = None,
                      var tags: List[String] = Nil
                      ) {

  def toMDocument: MDocument =
    new MDocument(creator, category, title, content, subtitle, description, slug)

  def removeTags(vs: List[String]): List[String] =
    vs diff tags

  def insertTags(vs: List[String]): List[String] =
    tags diff vs

  override def toString =
    s"creator: $creator, category: $category, title: $title, content: $content, subtitle: $subtitle, description: $description, slug: $slug, tags: $tags"
}
